﻿using System;
using System.Linq.Expressions;
using GalaSoft.MvvmLight;
using MvvmValidation;

namespace Budget.Silver.ViewModel
{
    public abstract class ValidatableViewModel : ViewModelBase
    {
        protected ValidationHelper Validator { get; private set; }

        protected ValidatableViewModel()
        {
            Validator = new ValidationHelper();

            AddValidationRules();
        }

        protected abstract void AddValidationRules();

        protected void ValidateAll()
        {
            var result = Validator.ValidateAll();
            if (!result.IsValid)
            {
                throw new ValidationException(result.ToString());
            }
        }
    }
}